package com.word.vacation.sdk;

import com.word.vacation.sdk.ad.WordVideoCallback;
import com.word.vacation.sdk.bridge.WordCocosBridge;
import com.word.vacation.sdk.ad.WordVideoManger;

import org.json.JSONObject;

public class WordAdSdk implements WordVideoCallback {
    private static WordAdSdk wordAdSdk;
    private String ad_source = "";

    public static WordAdSdk getInstance() {
        if (wordAdSdk == null) {
            wordAdSdk = new WordAdSdk();
        }
        return wordAdSdk;
    }

    public void showAd(String ad_source) {
        showAd(ad_source, 5);
    }

    private static void adCallBack(String state, String ad_source) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("ad_source", ad_source);
            WordCocosBridge.getInstance().XSSdkCallback(state, jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void showAd(String ad_source, int q) {
        this.ad_source=ad_source;
        showAd(this, q);
    }

    public static void showAd(WordVideoCallback callback, int i) {
        try {
            WordVideoManger.getReward1Instance().showVideo(WordCocosBridge.mainGameActivity.get(),callback);
        } catch (Exception e) {
            e.printStackTrace();
            callbackAdError(callback);
        }
    }


    private static void callbackAdError(WordVideoCallback callback) {
        if (callback != null) {
            callback.onAdError();
        }
    }


    @Override
    public void onAdOver() {
        adCallBack("ad_over_word", ad_source);
    }

    @Override
    public void onAdError() {
        adCallBack("ad_error_word", ad_source);
    }
}
